import { createRouter, createWebHashHistory, createWebHistory } from "vue-router";

// 路由懒加载 优化
// import HomeView from '@/views/HomeView.vue'
// import SearchView from '@/views/SearchView.vue'
// import NotFoundView from "@/views/NotFoundView.vue";

const router = createRouter({
  // history: createWebHashHistory(), // Hash 路由模式
  history: createWebHistory(), // 常规路由模式 需要运维工程师、后端工程师改配置 https://router.vuejs.org/zh/guide/essentials/history-mode.html#%E6%9C%8D%E5%8A%A1%E5%99%A8%E9%85%8D%E7%BD%AE%E7%A4%BA%E4%BE%8B
  routes: [
    { path: '/find', component: () => import('@/views/FindView.vue') },
    { path: '/my', component: () => import('@/views/MyView.vue') },
    { path: '/friend', component: () => import('@/views/FriendView.vue') },
    { path: '/search', component: () => import('@/views/SearchView.vue') },
    // redirect 重定向，避免首页白屏
    { path: '/', redirect: '/home' },
    { path: '/home', component: () => import('@/views/HomeView.vue') },
    // 可选动态路由参数，避免无参数时白屏
    { path: '/search/:keyword?', component: () => import('@/views/SearchView.vue') },
    { name: 'SearchView', path: '/search/:keyword?', component: () => import('@/views/SearchView.vue') },
    // 404 页面，路径不存在时，避免白屏
    { path: '/:pathMatch(.*)*', component: () => import('@/views/NotFoundView.vue') }
  ]
})

export default router